const seq = require('../db/seq');
const Goods = require('../model/goods');

const goods = Goods(seq);

class GoodsController {
    async showTea(ctx, next) {
        try {
            const res = await goods.findAll({ where: { goods_type: "茶叶" } });
            ctx.body = {
                code: 0,
                message: '获取茶叶信息成功',
                result: JSON.stringify(res)
            }
        } catch (err) {
            console.log(err);
            return ctx.body = {
                error: '获取茶叶信息失败'
            }
        }
    }

    async showTeaset(ctx, next) {
        try {
            const res = await goods.findAll({ where: { goods_type: "茶具" } });
            ctx.body = {
                code: 0,
                message: '获取茶具信息成功',
                result: JSON.stringify(res)
            }
        } catch (err) {
            console.log(err);
            return ctx.body = {
                error: '获取茶具信息失败'
            }
        }
    }

    async guangxiTea(ctx, next) {
        try {
            const res = await goods.findAll({ where: { goods_type: "茶叶" } });
            console.log(JSON.stringify(res));
            ctx.body = {
                code: 0,
                message: '获取地方茶信息成功',
                result: JSON.stringify(res)
            }
        } catch (err) {
            console.log(err);
            return ctx.body = {
                error: '获取地方茶信息失败'
            }
        }
    }
}

module.exports = new GoodsController();